var stream = weex.requireModule('stream');
var Host = 'http://eip7s3test.hkbf.com.cn/';

//! 转化工具

  function toParams(obj) {
    var param = ""
    for(const name in obj) {
        if(typeof obj[name] != 'function') {
            param += "&" + name + "=" + encodeURI(obj[name])
        }
    }
    return param.substring(1)
  }

  // 参数过滤函数
  function filterNull (obj) {
    for (var key in obj) {
      if (obj[key] === null) {
        delete obj[key]
      }
      if (typeof(obj[key]) === 'string') {
        obj[key] = obj[key].trim()
      } else if (typeof(obj[key]) === 'object') {
        obj[key] = filterNull(obj[key])
      } else if (typeof(obj[key]) === 'array') {
        obj[key] = filterNull(obj[key])
      }
    }
    return obj
  }


module.exports = {



  getFetch(url,params,success) {
   // 过滤参数
   if (params) {
     params = filterNull(params)
   }
console.log(Host+url);
console.log(toParams(params));

   stream.fetch({
     method:"POST",
     type:'json',
     url:Host+url,
     headers:{'Content-Type':'application/x-www-form-urlencoded'},
     body:toParams(params)
   }, function(ret){
     if (ret.ok) {
       // 解密
         console.log(ret.data);
         success(ret)
     } else {
       success(ret)
     }
   })

 },


 // postFetch (url,param,success) {
 //   return getFetch(url,param,success)
 // },

};
